<template>
	<view class="j_cont">
		<!-- 导航栏 -->
		<view class="j_top">
			<!-- 跳转图标 -->
			<view class="j_left_icon">
				<text @click="back">&lt;</text>
			</view>
			<!-- 标题 -->
			<view class="j_title">
				昵称
			</view>
			<!-- right -->
			<view class="j_ttip">
				<text @click="release">更新头像</text>
			</view>
		</view>
		<!-- 增加头像 -->
		<u-upload ref="uUpload" :action="action" :auto-upload="true" @on-success="uploadSuccess" max-count="1">
		</u-upload>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: undefined,
				action: 'http://127.0.0.1:7001/api/updateImg',
				items: {
					pin: '',
					img1: [],
					price: '',
					content: '',
					name: '小明',
					img: 'http://127.0.0.1:7001/public/cxyimg/cxy_5.png'
				}
			}
		},
		methods: {
			//返回上一级页面
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			//发布
			uploadSuccess(data, index, lists, name) {
				var arr = []
				lists.forEach(({
					response
				}) => {
					arr.push(`http://127.0.0.1:7001${response.data}`)
				})
				// console.log(arr)
				this.items.img1 = arr.join()
			},
			//更新头像

			release() {
				// this.$api.createMsg(this.items)
				// console.log(this.items.img1)
				this.$api.jiupMsg({
					id: this.id,
					avatar: this.items.img1
				}).then(res => {
					// console.log(res)
					if (res.code == 200) {
						uni.navigateBack({
							delta: 1
						})
					}
				})
			},

		},
		//获取你要更改数据的id
		onLoad(option) {
			this.id = option.id
		}

	}
</script>

<style lang="scss" scoped>
	.j_cont {
		width: 100%;
		height: 100vh;
		background: #F2F2F2;

		//导航栏
		.j_top {
			width: 100%;
			height: 80upx;
			background: white;
			padding: 0 20upx;
			box-sizing: border-box;
			line-height: 80upx;
			display: flex;

			//left
			.j_left_icon {
				width: 10%;
				height: 100%;

				font-size: 40upx;
				text-align: center;
			}

			//title
			.j_title {
				width: 70%;
				height: 100%;
				text-align: center;
			}

			//right
			.j_ttip {
				width: 20%;
				height: 100%;
				text-align: center;
				color: #FAAB34;
				font-size: 30upx;
			}
		}
	}
</style>
